package ee.homework.third;

import java.util.ArrayList;
import java.util.List;

/**
 * SkipList node counter
 * 
 * @author Kaarel Hanson
 * @since 08.03.2011
 */
public class SkipListNodes {

	private List<Integer> levels;

	public static void main(String[] args) {
		SkipListNodes sln = new SkipListNodes();
		for (int i = 100; i < 1000000000; i = i * 10) {
			sln.addNode(i);
			for (int j = 0; j < sln.levels.size(); j++) {
				System.out.println("Elements: " + i);
				System.out.println("Level " + (j + 1) + ", elements: "
						+ sln.levels.get(j));
			}
			System.out.println();
			sln.levels.clear();
		}
	}

	public void addNode(int arraySize) {
		levels = new ArrayList<Integer>();
		int counter;
		for (int i = 0; i < arraySize; i++) {
			counter = 0;
			int x;
			do {
				x = (int) (Math.random() * 2);
				counter++;
			} while (x > 0);
			for (int j = 0; j < counter; j++) {
				if (levels.size() < j + 1) {
					levels.add(j, 1);
				} else {
					levels.set(j, levels.get(j) + 1);
				}

			}
		}
	}
}
